package com.example.ayelet;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.ayelet.Imagelabels.ImageAndLabels;
import com.google.protobuf.InvalidProtocolBufferException;


public class LearnEnglish extends Activity {
	
	private ImageView ivImageView;
	private ImageAndLabels imagelabels = null;
	protected static final int AMIR_ACTIVITY = 0;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_learn_english);
        
        ivImageView = (ImageView) findViewById(R.id.ivImageView);
        
        if (imagelabels == null)
        {
        	Intent intent = new Intent(this, ChoosePhotosActivity.class);
        	startActivityForResult(intent, AMIR_ACTIVITY);
        }
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // Check which request we're responding to
        if (requestCode == AMIR_ACTIVITY) {
            // Make sure the request was successful
            if (resultCode == RESULT_OK) {
                // The user picked a contact.
                // The Intent's data Uri identifies which contact was selected.
            	try {
					imagelabels = ImageAndLabels.parseFrom(data.getByteArrayExtra("labels"));
					NextImage();
				} catch (InvalidProtocolBufferException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
                // Do something with the contact here (bigger example below)
            }
        }
    }
    
    private void NextImage()
    {
    	Toast.makeText(this, "NextImage", Toast.LENGTH_LONG).show();
    	NextImage(null);
    }
    
    public void NextImage(View vSourceView)
    {
    	// Getting random image
    	//int nNextImageResource = GetResourceByUri(uNextImage);
    	
    	Uri uTemp = Uri.parse(imagelabels.getImages(0).getUri());
    	
    	// Setting the new image
    	ivImageView.setImageURI(uTemp);
    }
    
    public void Echo(View vSourceView)
    {
    	
    }
}
